#! /usr/bin/env python
# -*- coding:utf-8 -*-

# python观看免费腾讯视频vip电影

import tkinter.messagebox as msgbox
from urllib.parse import quote_plus
import tkinter as tk
import webbrowser
import re


#https://www.bilibili.com/video/av372590519/
#自定义一个类
class App:
    def __init__(self, width = 500, height = 300):
        self.w = width
        self.h = height
        self.title = '腾讯vip付费电影免费看'
        self.root = tk.Tk(className=self.title)
        #地址变量
        self.url = tk.StringVar()
        # 小型框架(小组件)
        frame_1 = tk.Frame(self.root)
        lable = tk.Label(frame_1, text='视频地址:')
        entry = tk.Entry(frame_1, textvariable=self.url, width=35)
        play = tk.Button(frame_1, text='播放',font=('楷体', 12), fg='red', width=2, height=1, command=self.video_play)
        frame_1.pack()
        # 小组件关系如何控制
        lable.grid(row=0, column=0)
        entry.grid(row=0, column=1)
        play.grid(row=0, column=2, ipadx=12, ipady=12)

    def video_play(self):   #核心
        port = 'http://www.wmxz.wang/video.php?url='
        #拦截
        regx = '^https?:/{2}\w.+$'
        ips = self.url.get()
        if re.match(regx, ips):
            #包装
            ip = quote_plus(ips)
            webbrowser.open(port + ip)
        else:
            msgbox.showerror(title='警告错误', message='视频地址无效，请重新输入!')

    def loop(self):
        self.root.resizable(True, True)
        self.root.mainloop()

if __name__ == "__main__":
    app = App()
    app.loop()        
